

import { defHttp } from '@/utils/http/axios';
import { RequestEnum } from '@/enums/httpEnum';
import { ServicePrefixEnum } from '@/enums/commonEnum';
import type { AxiosRequestConfig } from 'axios';

export interface DeptVO {
  id?: number
  name: string
  parentId: number
  status: number
  sort: number
  leaderUserId: number
  phone: string
  email: string
  createTime: Date
}

const MODULAR = '/system/dept';

export const Api = {
  GetSimpleDeptList: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/simple-list`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetDeptPage: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/list`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  GetDept: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/get`,
    method: RequestEnum.GET,
  } as AxiosRequestConfig,
  CreateDept: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/create`,
    method: RequestEnum.POST,
  } as AxiosRequestConfig,
  UpdateDept: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/update`,
    method: RequestEnum.PUT,
  } as AxiosRequestConfig,
  DeleteDept: {
    url: `${ServicePrefixEnum.BASE}/${MODULAR}/delete`,
    method: RequestEnum.DELETE,
  } as AxiosRequestConfig,
}

// 查询部门（精简)列表
export const getSimpleDeptList = () => {
  return defHttp.request({ ...Api.GetSimpleDeptList})
}
// 查询部门列表
export const getDeptPage = (params: PageParam) => {
  return defHttp.request({ ...Api.GetDeptPage,params: params })
}
// 查询部门详情
export const getDept = (id: number) => {
  let params = {id: id}
  return  defHttp.request({ ...Api.GetDept,params:params })
}

// 新增部门
export const createDept = async (data: DeptVO) => {
  let params = {data: data}
  return defHttp .request({ ...Api.CreateDept,params:params })
}

// 修改部门
export const updateDept = async (data: DeptVO) => {
  let params = {data: data}
  return defHttp.request({ ...Api.UpdateDept,params:params })
}

// 删除部门
export const deleteDept = (id: number) => {
  let params = {id: id}
  return defHttp.request({ ...Api.DeleteDept,params:params })
}








